<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.*,com.dican.portal.beans.PedidoConsulta, java.text.*;" errorPage=""%>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%! DateFormat tipe = new SimpleDateFormat("EEE, MMM d, yyyy");
    Calendar cal = Calendar.getInstance();%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="includes/estilo.css" rel="stylesheet" type="text/css">
<title>Lista de itens do pedido</title>
</head>
<body onLoad="this.focus();">
<table border="0" align="center" cellpadding="0" cellspacing="0" width="770px">
	<tr>
		<td height="100px">
			<table border="0" align="center" cellpadding="0" cellspacing="0" width="100%">
			<tr>
				<td align="center" width="100px"> <font color="#191970" size="1"><%=(tipe.format(cal.getTime()))%></font></td>
				<td width="30px"></td>
				<td><center><b><font color="blue" size="4">Itens do pedido: <%=request.getParameter("numPedido")%></font><br/><font color="navy" size="2">Status: <%=request.getParameter("docstatus") %></font></b></center></td>
				<td align="right" width="100px"><img src="imagens/logoDican.jpg" width="100px"></td>
			</tr>
			<tr>
				<td colspan=4 align="right"><input name="Button" type="button" class="botaoazul" style="width:80px" value="Imprimir" onclick="javascript:window.open('ImprimePedido?pedId=<%=request.getParameter("orderId") %>&relatname=Rpt_Brcore_SalesOrder','_newtab');"></td>
			</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td><font size="1">Os itens e o pedido est&atilde;o sujeitos a altera&ccedil;&atilde;o</font></td>
	</tr>
	<tr>
		<td><hr color=navy size=3></td>
	</tr>
	<tr>
		<td>
			<table align="center" cellpadding="0" cellspacing="0" width="100%" style="border-bottom: solid 2px black;margin-bottom: 20px">
				<tr bgcolor="#696969" height="25px">
					<td align="center" width="120px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>PEDIDO</b></font></td>
					<td align="center" width="90px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>ORIGEM</b></font></td>
					<td align="left" width="440px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>CLIENTE</b></font></td>
					<td align="center" width="120px" align="left" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>EMISS&Atilde;O</b></font></td>
				</tr>
				<tr bgcolor="#FFFFFF" height="30px">
					<td align="center" style="border-top: solid 1px black; border-left: solid 2px black;"><font size="1"><%=request.getParameter("numPedido")%></font></td>
					<td align="center" style="border-top: solid 1px black; "><font size="1"><%=request.getParameter("org")%></font></td>
					<td style="border-top: solid 1px black;"><font size="1"><%=request.getParameter("clienteNome")%></font></td>
					<td align="center" style="border-top: solid 1px black;border-right: solid 2px black;"><font size="1">&nbsp;<%=request.getParameter("emissao")%></font></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table align="center" cellpadding="0" cellspacing="0" width="100%" style="border-bottom: solid 2px black;margin-bottom: 10px">
				<tr bgcolor="#696969" height="25px">
					<td align="center" width="120px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>CODIGO</b></font></td>
					<td align="left" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>DESCRI&Ccedil;&Atilde;O</b></font></td>
					<td align="center" width="120px" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>QUANTIDADE</b></font></td>
				</tr>
				<sql:query dataSource="jdbc/postgres" var="itensPedido">
					SELECT M.value as codProd, M.name as descrProd, OL.qtyordered as OLqtyordered 
					FROM C_ORDERLINE OL 
					INNER JOIN M_PRODUCT M ON OL.m_product_id = M.m_product_id 
					WHERE OL.c_order_id = ? ORDER BY M.value ASC;
					<sql:param><%=request.getParameter("orderId") %></sql:param>
				</sql:query>
				<c:forEach var="itenPedido" items="${itensPedido.rows}" varStatus="count">
				<tr class="${count.index % 2 == 0 ? 'even' : 'odd'}" height="30px">
					<td align="center" style="border-top: solid 1px black;border-left: solid 2px black;"><font size="1">${itenPedido.codProd}</font></td>
					<td align="left" style="border-top: solid 1px black;"><font size="1">${itenPedido.descrProd}</font></td>
					<td align="center" style="border-top: solid 1px black;border-right: solid 2px black;"><font size="1">${itenPedido.OLqtyordered}</font></td>
				</tr>
				</c:forEach>
			</table>
			<table align="center" cellpadding="0" cellspacing="0" width="100%" style="border-bottom: solid 2px black;margin-bottom: 10px">
				<tr>
					<td colspan="3"><hr color=navy size=3></td>
				</tr>
				<tr bgcolor="#696969" height="25px">
					<td colspan="3" align="center" style="border-bottom: solid 2px black;"><font color="#FFFFFF" size="1"><b>HIST&Oacute;RICO DO PEDIDO</b></font></td>
				</tr>
				<tr bgcolor="#BEBEBE" height="25px">
					<td align="left" style="padding-left: 10px;border-bottom: solid 1px black;"><font color="#000000" size="1">Data</font></td>
					<td align="left" style="border-bottom: solid 1px black;"><font color="#000000" size="1">Ocorr&ecirc;ncia</font></td>
					<td align="left" style="border-bottom: solid 1px black;"><font color="#000000" size="1">Observa&ccedil;&atilde;o</font></td>
				</tr>
				<sql:query dataSource="jdbc/postgres" var="ocorrencias">
					SELECT em_nfe_chaveacesso,em_nfe_mensagem,em_nfe_dataenvio
					FROM C_INVOICE WHERE
					C_ORDER_ID=? AND
					docstatus='CO' ORDER BY em_nfe_dataenvio ASC;
					<sql:param><%=request.getParameter("orderId") %></sql:param>
				</sql:query>
				<c:forEach var="ocorrencia" items="${ocorrencias.rows}" varStatus="count">
				<tr class="${count.index % 2 == 0 ? 'even' : 'odd'}" height="30px">
					<td align="center" style="border-top: solid 1px black;border-left: solid 2px black;"><font size="1">${ocorrencia.em_nfe_dataenvio}</font></td>
					<td align="left" style="border-top: solid 1px black;"><font size="1">${ocorrencia.em_nfe_mensagem}</font></td>
					<td align="center" style="border-top: solid 1px black;border-right: solid 2px black;"><font size="1">CHAVE DE ACESSO ${ocorrencia.em_nfe_chaveacesso}</font></td>
				</tr>
				</c:forEach>
			</table>
		</td>
	</tr>
</table>
</body>
</html>